package com.northone.statistics.utils;

import com.northone.statistics.database.SaintDataBaseHelper;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Handler;
import android.os.Message;

public class QueryDBUtil extends Thread {
	/** 查询圣徒 */
	public static void queryAllSaint(final SQLiteDatabase db, final Handler handler) {
		new Thread(new Runnable() {
			public void run() {
				Cursor cursor = db.query(SaintDataBaseHelper.TABLE_NAME_BASE, null, null, null, null, null, null);
				Message msg = Message.obtain();
				msg.obj = cursor;
				msg.what = Constans.QUERY_ALL_SAINT;
				handler.sendMessage(msg);
			}
		}).start();
		
	}

	/** 搜索圣徒 */
	public static void searchSaint(final SQLiteDatabase db, final Handler handler, final String query) {
		new Thread(new Runnable() {
			public void run() {
				Cursor cursor_like = db.query(SaintDataBaseHelper.TABLE_NAME_BASE, null, "name LIKE ? ",
						new String[] { "%" + query.trim() + "%" }, null, null, null);
				Message msg = Message.obtain();
				msg.obj = cursor_like;
				msg.what = Constans.SEARCH_SAINT;
				handler.sendMessage(msg);
			}
		}).start();
	}
}
